package cqie.cn.frame.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 王林
 * @version 1.0
 * @date 2021-09-11 周六
 * @time 0:42
 * @description
 */
//@Configuration
public class InterceptConfig extends WebMvcConfigurationSupport {

//    private TokenInterceptor tokenInterceptor;
//
//    //构造方法
//    public InterceptConfig(TokenInterceptor tokenInterceptor) {
//        this.tokenInterceptor = tokenInterceptor;
//    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("swagger-ui.html")
                .addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("doc.html").addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/");

    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        List<String> excludePath = new ArrayList<>();
        excludePath.add("/login"); //登录
//        excludePath.add("/logout"); //登出
        excludePath.add("/static/**");  //静态资源
        excludePath.add("/assets/**");  //静态资源
        // swagger过滤
        excludePath.add("/favicon.ico");
        excludePath.add("/actuator/health/**");
        excludePath.add("/v2/api-docs/**");
        excludePath.add("/v2/**");
        excludePath.add("/v3/**");
        excludePath.add("/v2/api-docs-ext/**");
        excludePath.add("/swagger-resources");
        excludePath.add("/error/**");
        excludePath.add("/webjars/**");
        excludePath.add("/swagger-ui.html");
        excludePath.add("/doc.html");

//        registry.addInterceptor(tokenInterceptor)
//                .addPathPatterns("/**")
//                .excludePathPatterns(excludePath);
        super.addInterceptors(registry);
    }

}
